import 'package:flutter/material.dart';
import 'messageDetailPage.dart';
class messagePage extends StatefulWidget{

  const messagePage({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState()=>messagePageState();

}

class messagePageState extends State<messagePage>{
  List messageList=[
    {
      "headPic":"images/pic1.jpg",
      "title":'只等逍遥',
      "subtitle":'走，干饭去！',
      "time":'11:25',
    },
    {
      "headPic":"images/pic2.jpg",
      "title":'软件20级暂缓返校',
      "subtitle":'[有人@我]：省内返校记得三天两...',
      "time":'12:51',
    },
    {
      "headPic":"images/pic3.jpg",
      "title":'ikun',
      "subtitle":'跟你说我会唱跳rap还有篮球[动画...',
      "time":'13:23',
    },
    {
      "headPic":"images/pic4.jpg",
      "title":'阿湫',
      "subtitle":'can can need[动画表情]',
      "time":'14:06',
    },
    {
      "headPic":"images/pic10.jpg",
      "title":'看见我请叫我去学六级',
      "subtitle":'真的难受QAQ，一起加油吧',
      "time":'15:12',
    },
    {
      "headPic":"images/pic6.jpg",
      "title":'1！5！',
      "subtitle":'芝士雪豹见过吧',
      "time":'17:12',
    },
    {
      "headPic":"images/pic9.jpg",
      "title":'西科大谦友群',
      "subtitle":'新歌!朋友们,我才听到，原来...',
      "time":'昨天',
    },
    {
      "headPic":"images/pic8.jpg",
      "title":'芭芭拉冲呀',
      "subtitle":'你什么时候回坑啊，这新版本多好...',
      "time":'昨天',
    },
    {
      "headPic":"images/pic5.jpg",
      "title":'记得早睡',
      "subtitle":'我真的服了，昨晚又是2点多才弄...',
      "time":'昨天',
    },
    {
      "headPic":"images/pic7.jpg",
      "title":'YOLO',
      "subtitle":'水逆退散，万事胜意',
      "time":'昨天',
    },
  ];

  Widget getData(context,index){
    return ListTile(
      title: Text(messageList[index]['title']),
      subtitle: Text(messageList[index]['subtitle']),
      leading: CircleAvatar(backgroundImage: AssetImage(messageList[index]['headPic'])),
      trailing: Text(messageList[index]['time']),
      onTap: (){
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (BuildContext context) {
          return messageDetailPage(
              title:messageList[index]['title'],
              subtitle:messageList[index]['subtitle'],
              pic:messageList[index]['headPic']
          );
        }));
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: getListView(),
    );
  }
  ListView getListView(){
    return ListView.builder(
      itemCount: messageList.length,
      itemBuilder: this.getData,
    );
  }
}